package com.samskievert.cactusboom;

import java.awt.AlphaComposite;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Color;
import java.awt.Polygon;
import com.threerings.media.sprite.Sprite;
import java.awt.geom.AffineTransform;
import com.threerings.util.Name;

/**
 * Displays a "potential move" cursor to the player.
 */
public class DataSprite extends Sprite
{
    public static final int SIZE = 120;
    public int whichplayer;
    private CBObject _gameobj;
    
    public DataSprite (CBObject gameobj, int wp)
    {
        super(SIZE, SIZE);
        _comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
        
        whichplayer = wp;
        _gameobj = gameobj;
    }

    @Override // from CactusSprite
    public void paint (Graphics2D gfx)
    {
        Composite ocomp = gfx.getComposite();
        gfx.setComposite(_comp);
        gfx.setColor(Color.black);     
        
        if(_gameobj != null){
            Name[] names = _gameobj.getPlayers();
            if(whichplayer < names.length){  //only draw if this player is in the room
            
            //if i am the active player, draw a box around me
            if(names[whichplayer].equals(_gameobj.getTurnHolder())){
                int bx = _bounds.x; int bw = _bounds.width;
                int by = _bounds.y; int bh = 70;
                Color[] COLORLIST = new Color[] {Color.blue, Color.red, Color.green, Color.orange};
                gfx.setColor(COLORLIST[whichplayer]);
                gfx.fillRect(bx,by,bw,5);
                gfx.fillRect(bx,by,5,bh);
                gfx.fillRect(bx,by+bh-5,bw,5);
                gfx.fillRect(bx+bw-5,by,5,bh);
                gfx.setColor(Color.black);
                gfx.drawRect(bx,by,bw-1,bh-1);
                gfx.drawRect(bx+5,by+5,bw-10,bh-10);
            }
                
            Font font =  new Font("arial",0,14);
            gfx.setFont(font);
            String name = names[whichplayer].toString();
            FontMetrics fm = gfx.getFontMetrics();
            int nameW = fm.stringWidth(name);
            
            gfx.drawString(name, _bounds.x + 52 - nameW/2, _bounds.y + 64);
            
            
            font =  new Font("arial",0,10);
            gfx.setFont(font);
            int[] numTerrs = new int[_gameobj.getPlayers().length];
            if(_gameobj.turnPoints != null){ 
                for(CBObject.Claim claim : _gameobj.claims){
                if(claim.owner >= 0) {
                    if(claim.owner >= 0) numTerrs[claim.owner]++;
                }
             }
                
                gfx.drawString("Moves: " + _gameobj.movePoints[whichplayer], _bounds.x + 52, _bounds.y + 18);
                gfx.drawString("Claims: " + numTerrs[whichplayer],_bounds.x + 52, _bounds.y + 30);
                /*
                gfx.drawString("CP:" + _gameobj.turnPoints[whichplayer], _bounds.x + 48, _bounds.y + 30);
                gfx.drawString("MP:" + _gameobj.movePoints[whichplayer], _bounds.x + 74, _bounds.y + 30);
                gfx.drawString("LV:" + _gameobj.livesLeft[whichplayer], _bounds.x + 48, _bounds.y + 42);
                gfx.drawString("SC:" + _gameobj.explosions[whichplayer], _bounds.x + 74, _bounds.y + 42);
                 **/
                
                }
            }else{
            System.out.println("Didn't feel like it. (" + whichplayer + " vs " + names.length + ")");   
            }
        }else{
            System.out.println("Seems like gameobj is null.");
        }
        gfx.setComposite(ocomp);
        
  }
    

   protected AlphaComposite _comp;
}

